<?php
namespace  Api\Controller;
class HelpController extends ApiController{
    
    /**
     * 帮助列表
     */
    public function articles(){
        $M_article=M('help');
        
        $top=$M_article->where(array('pid'=>0))->order('sort')->field('id,title,description,pid,sort')->select();
        foreach ($top as &$item){
            $item['_child']=$M_article->where(array('pid'=>$item['id']))->field('id,title,description,pid,sort')->select();
        }
        
        $top ? response(1,$top) : response(-2);
    }
    
    /**
     * 帮助列表
     * @param int pid
     */
    public function getChilds(){
        $M_article=M('help');
        params_exist('id');
        $id=I('id');
       
        $list=$M_article->where(array('pid'=>$id))->field('id,title,description,pid,sort')->select();
        
        $list ? response(1,$list) : response(-2);
        
    }
    
    /**
     * 帮助列表
     */
    public function articleDetail(){
        $M_article=M('help');
        params_exist('id');
        $id=I('id');
        $info=$M_article->find($id);
        empty($info) && response(-2,'','文章不存在'); 
        response(1,$info) ;
    }
    

    
    /**
     * 意见反馈
     */
    public function feedback(){
        params_exist('description');
        $data=array();
        $data['description']=I('post.description');
        
    }
    
    /*
     * @param string  $content
     */
    public function postFeedback()
    {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
    
        params_exist('content');
        $content = I('post.content');
        ! preg_match('/^.{3,250}$/', $content) && response(- 1, '反馈意见不能少于5字，不能多于250字');
        $map = array(
            'createtime' => NOW_TIME,
            'content' => $content,
            'uid'=>API_UID
        );
         
        $result = M('feedback')->add($map);
        if ($result) {
            response(1, '', '反馈成功');
        } else {
            response(-1);
        }
    }
}
?>